// pages/finishorderdetail/finishorderdetail.js
var that,
api = new(require('../../utils/api.js')),
headimg = api.getimgurl(),
util = new(require('../../utils/util.js'));
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderdata:'',
    recycle:'',
    type:'',
    target:[],
    headimg,
    picpath:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    that=this
    let {ordernum} =options
    that.setData({ordernum},()=>{
      that.getdata()
    })

  },
  getdata(){
    let {ordernum,orderdata,recycle,type,target,picpath} = that.data,newpicpath=[]
    api.getfinishorderdetail(ordernum,res=>{
      if(res.data.issuccess==1){
        console.log(res.data.data,'getorderdetail');
        orderdata=res.data.data
        orderdata.price=(orderdata.price/100).toFixed(2)
        if(orderdata.picpath!=null){
          picpath = orderdata.picpath.split(',');
        }
        picpath.forEach(x=>{
          console.log( headimg+x,'xxxxx');
          newpicpath.push( headimg + x) 
        })
        orderdata.orderDate =util.toDate1(orderdata.orderDate)//util.formatTimenosecend(new Date(orderdata.orderDate))
        orderdata.finishDate =util.toDate1(orderdata.finishDate)//util.formatTimenosecend(new Date(orderdata.finishDate)) 
        type=res.data.type
        recycle =res.data.recycle
        res.data.target.forEach(x=>{
          x.apply.weight=(x.apply.weight/1000).toFixed(2)
          x.apply.price=(x.apply.price/100).toFixed(2)
        })
        target=res.data.target
        that.setData({orderdata,recycle,type,target,picpath,newpicpath})
      }
    })
  },
  preview(e) {
    console.log(e.currentTarget.dataset.src)
    let currentUrl = e.currentTarget.dataset.src
    wx.previewImage({
      current: currentUrl, 
      urls:that.data.newpicpath
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})